
**********
* Readme *
**********

* This script combines the parameters (from previous steps) according to the structural model.


* Root folder (PATH TO BE DEFINED BY THE USER)
**********************************************
clear all
global analysis "C:/***/replication_package"


* Timestamped log
*****************
global today = strofreal(date(c(current_date), "DMY"), "%tdYYNNDD")
log using "${analysis}/code/logs/5_model_${today}.smcl", replace


*******************************
* How many bootstraps rounds? *
*******************************

global B = 400


******************************************************
* Store average interest rates in the period 2017-18 *
****************************************************** 

use "${analysis}/data/1_3_aux_market_rates.dta", clear

* Market rates from 2017 to 2018
sum market_rates if date > mofd(date("201612", "YM")) & date < mofd(date("201901", "YM"))
global avg_r = r(mean)
di $avg_r


*************************************
* Gathering the pieces of the model *
*************************************

use "${analysis}/data/2_2_pof_clean.dta", clear
svyset psu_id [pweight = pweight], strata(strata_id) singleunit(centered) 
gen fweight = round(pweight)
keep strata_id psu_id ind_id pweight fweight work_state_name work_state_ibge_name winc ln_winc

* Market rates from 2017 to 2018
gen avg_r = $avg_r
label var avg_r "Monthly interest rate for personal credit (2017-18 average)"

* Empirical dispersion of log wages (baseline)
svy, subpop(if work_state_name == "Employee"): mean ln_winc
estat sd
matrix temp = r(sd)
gen est_ln_wage_sd = temp[1,1]

* Empirical dispersion of log wages (domestic workers as employees)
svy, subpop(if work_state_ibge_name == "Employee"): mean ln_winc
estat sd
matrix temp = r(sd)
gen appx_dom_est_ln_wage_sd = temp[1,1]

* Merge fitted values to it
merge 1:1 ind_id using "${analysis}/data/4_1_est_potential_wages.dta", nogenerate
merge 1:1 ind_id using "${analysis}/data/4_2_est_reservation_wages.dta", nogenerate
merge 1:1 ind_id using "${analysis}/data/4_3_est_hazards.dta", nogenerate
merge 1:1 ind_id using "${analysis}/data/4_4_appx_dom_est_hazards.dta", nogenerate
merge 1:1 ind_id using "${analysis}/data/4_5_appx_rew_est_hazards.dta", nogenerate
merge 1:1 ind_id using "${analysis}/data/4_6_est_boot_wages.dta", nogenerate

describe
save "${analysis}/data/5_model_pieces.dta", replace


*****************************
* BASELINE / 05 10 15 / rew *
*****************************

use "${analysis}/data/5_model_pieces.dta", clear
svyset psu_id [pweight = pweight], strata(strata_id) singleunit(centered) 

* Focus on OAW only (baseline)
tab work_state_name
gen       winc_oaw = winc if work_state_name == "Own-account worker"
label var winc_oaw "Own-account workers' net available work income"
tab work_state_name

gen status_oaw = (work_state_name == "Own-account worker")
gen status_ee = (work_state_name == "Employee")

tab work_state_name status_oaw
tab work_state_name status_ee


* Part A. Estimating rho
************************


* Note on offer arrival rate
****************************
* We estimated the unemployment-into-employment transition hazard (h)
* which is a combination of the offer arrival rate lambda AND the probability of receiving an acceptable offer: 
* h = lambda * prob(offer > wr)   and   lambda = h / prob(offer > wr) 
* where prob(offer > rw) = 1 - Phi( (ln wr - ln wage) / sd(ln wage) ), for ln offer ~ N(ln est wage i, sd(ln wage)^2)

* Estimated prob of acceptable offer
gen prob_accept_05_0 = 1 - normal( (est_ln_rw_05_0 - est_ln_wage_0) / est_ln_wage_sd )
gen prob_accept_10_0 = 1 - normal( (est_ln_rw_10_0 - est_ln_wage_0) / est_ln_wage_sd )
gen prob_accept_15_0 = 1 - normal( (est_ln_rw_15_0 - est_ln_wage_0) / est_ln_wage_sd )

sum prob_accept_05_0 prob_accept_10_0 prob_accept_15_0 [fweight = fweight], detail

* Estimated duration of unemployment
gen avg_unemp = 1 / haz_from_u_to_e_0
gen appx_rew_avg_unemp = 1 / appx_rew_haz_from_u_to_e_0

sum haz_from_u_to_e_0 appx_rew_haz_from_u_to_e_0 avg_unemp appx_rew_avg_unemp [fweight = fweight], detail

* Estimated offer arrival rate lambda
gen l_05_0 = haz_from_u_to_e_0 / prob_accept_05_0
gen l_10_0 = haz_from_u_to_e_0 / prob_accept_10_0
gen l_15_0 = haz_from_u_to_e_0 / prob_accept_15_0

gen appx_rew_l_10_0 = appx_rew_haz_from_u_to_e_0 / prob_accept_10_0

* Estimated wait time for an offer
gen avg_wait_05_0 = 1 / l_05_0
gen avg_wait_10_0 = 1 / l_10_0
gen avg_wait_15_0 = 1 / l_15_0

gen appx_rew_avg_wait_10_0 = 1 / appx_rew_l_10_0

sum        l_05_0        l_10_0        l_15_0        appx_rew_l_10_0 ///
    avg_wait_05_0 avg_wait_10_0 avg_wait_15_0 appx_rew_avg_wait_10_0 [fweight = fweight], detail

    
* Estimate rho lower bound (baseline and alternative specs)
***********************************************************

* Alternative specs for reservation wage
gen rho_05_0 = (l_05_0 / winc_oaw) * (est_wage_0 - est_rw_05_0 * prob_accept_05_0) - haz_out_of_e_0
gen rho_10_0 = (l_10_0 / winc_oaw) * (est_wage_0 - est_rw_10_0 * prob_accept_10_0) - haz_out_of_e_0 // BASELINE
gen rho_15_0 = (l_15_0 / winc_oaw) * (est_wage_0 - est_rw_15_0 * prob_accept_15_0) - haz_out_of_e_0

* Alternative specs for risk aversion
global risk_aversion 0.43

gen rho_10_risk_43 = (l_10_0 / winc_oaw^(1-$risk_aversion) ) * (est_wage_0^(1-$risk_aversion) - est_rw_10_0^(1-$risk_aversion) * prob_accept_10_0) - haz_out_of_e_0

* Alternative specs for survey weights
gen appx_rew_rho_10_0  = (appx_rew_l_10_0 / winc_oaw) * (est_wage_0 - est_rw_10_0 * prob_accept_10_0) - appx_rew_haz_out_of_e_0

sum rho_05_0 rho_10_0 rho_15_0 appx_rew_rho_10_0 rho_10_risk_43 [fweight = fweight], detail


* DESCRIPTIVE STATS for model components (baseline and alternative specs)
*************************************************************************

global model_pieces l_10_0 haz_out_of_e_0 prob_accept_10_0 est_rw_10_0 winc_oaw est_wage_0 

* Mean and standard deviation, BASELINE
qui svy, subpop(status_oaw): mean $model_pieces
estat sd

matrix mean = r(mean)
matrix rownames mean = "mean"

matrix sd = r(sd)
matrix rownames sd = "sd"

matrix mean_sd = ( mean \ sd )
matrix list mean_sd

* Quartiles, BASELINE
cap matrix drop quartiles_all
foreach piece of global model_pieces {
    
    epctile `piece', svy percentiles(25 50 75) subpop(status_oaw)

    matrix quartiles_`piece' = r(table)
    matrix quartiles_`piece' = quartiles_`piece'["b", 1...]
    matrix rownames quartiles_`piece' = "`piece'"

    capture confirm matrix quartiles_all
    
    if _rc == 111 {
    
        matrix quartiles_all = quartiles_`piece'
    
    }
    else {

        matrix quartiles_all = ( quartiles_all \ quartiles_`piece' )
         
    }
}

matrix quartiles_all = quartiles_all'
matrix list quartiles_all


* Summary table
***************

matrix summary = ( mean_sd \ quartiles_all )
matrix list summary
estadd matrix summary

esttab, varwidth(30) ///
  mgroups(none) mlabels(none) collabels(none) eqlabels(none) nonumber unstack noobs ///
  cells("summary[mean](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[sd](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[p25](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[p50](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[p75](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc))") ///
  varlabels( ///
    l_10_0              "Job offer arrival rate" ///
    haz_out_of_e_0      "Job destruction rate" ///
    prob_accept_10_0    "Prob. of receiving acceptable offer" ///
    est_rw_10_0         "Reservation wage" /// 
    winc_oaw            "Observed income from OAW" ///
    est_wage_0          "Expected wage") ///
  refcat( ///
    l_10_0              "Transition components" ///
    est_rw_10_0         "Earnings components", nolabel)


* TABLE 4
*********

esttab using "${analysis}/results/tables/table4.tex", style(tex) fragment replace ///
  mgroups(none) mlabels(none) collabels(none) eqlabels(none) nonumber unstack noobs ///
  cells("summary[mean](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[sd](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[p25](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[p50](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc)) summary[p75](fmt(%9.2fc %9.2fc %9.2fc %9.0fc %9.0fc %9.0fc))") ///
  varlabels( ///
    l_10_0              "\hspace{2ex} Estimated job offer arrival rate $ [\lambda] $" ///
    haz_out_of_e_0      "\hspace{2ex} Estimated job destruction rate $ [\delta] $" ///
    prob_accept_10_0    "\hspace{2ex} Estimated prob. of acceptable offer $ [\text{P}(w \geq w_r)] $" ///
    est_rw_10_0         "\hspace{2ex} Estimated reservation wage $ [w_r] $" /// 
    winc_oaw            "\hspace{2ex} Observed income from own-account work $ [y] $" ///
    est_wage_0          "\hspace{2ex} Estimated potential wage $ [w \,|\, w > w_r] $") /// 
  refcat( ///
    l_10_0          "\textit{Transition components} " ///
    est_rw_10_0        "\tabularnewline \textit{Earnings components (in money)}", nolabel) ///
    substitute("money" "R\\$" "  " " " "  " " " "  " " " \hline "")

    
* Estimate rho lower bound (resampling baseline)
************************************************

forvalues b = 1/$B {
  display `b'
  gen prob_accept_10_`b' = 1 - normal( (est_ln_rw_10_`b' - est_ln_wage_`b') / est_ln_wage_sd )
  gen rho_10_`b' = (((haz_from_u_to_e_`b' / prob_accept_10_`b') / winc_oaw) * (est_wage_`b' - est_rw_10_`b' * prob_accept_10_`b')) - haz_out_of_e_`b'
}

* Inference using the bootstrapped rhos
unab resamplings : rho_10_*
egen rho_ci_low = rowpctile(`resamplings'), p(5) 
egen rho_avg = rowmean(`resamplings')
egen rho_sd = rowsd(`resamplings')
egen rho_ci_high = rowpctile(`resamplings'), p(95) 

* Store results from bootstrapped rhos
drop est_ln_wage_* est_wage_* est_ln_rw_* est_rw_* haz_from_u_to_e_* appx_rew_haz_from_u_to_e_* haz_out_of_e_* appx_rew_haz_out_of_e_* prob_accept_* l_* appx_rew_l_* avg_unemp avg_wait_05_0 avg_wait_10_0 appx_rew_avg_wait_10_0 avg_wait_15_0
describe

* Focus on OAW only
keep if !missing(winc_oaw)

save "${analysis}/data/5_est_boot_rho.dta", replace


* Part B. Calculating the CDF
*****************************

use "${analysis}/data/5_est_boot_rho.dta", clear
svyset psu_id [pweight = pweight], strata(strata_id) singleunit(centered) 


* Summary of rho
****************

sum rho_10_0 [fweight = fweight], detail

* Memento: for correct standard errors, use commands below (point estimates are the same) 
* svy: mean rho_10_0
* epctile rho_10_0, svy percentiles(25 50 75)

* Trimmed at 1%
sum rho_10_0 if rho_10_0 > -0.141 & rho_10_0 < 2.11 [fweight = fweight], detail


* Empirical CDF
***************

* Given the survey design, we can't simply use the cumul function to get the CDF
* Instead, we will take the CDF as the inverse of the quantiles estimated with the program epctile
* The respective x and y coordinated for the baseline and bootstrapped curves are stored in a matrix

* Centiles of interest: y-axis goes from .01 to .99 in steps of .0025
gen double y = _n/400 + 0.0075 if _n < 394

* Centiles of interest: same thing, in a list to be passed to the command epctile 
numlist "1(0.25)99"
global p_list = "`r(numlist)'"


* Centiles estimation for alternative specifications
****************************************************

foreach spec in "05" "10" "15" {
  qui epctile rho_`spec'_0, svy percentiles($p_list) 
  matrix b = e(b)           // get the estimates 
  matrix x = b'             // transpose to a row vector
  svmat double x            // save as a variable
  rename x1 x_`spec'_0      // named x_*
}

qui epctile appx_rew_rho_10_0, svy percentiles($p_list) 
matrix b = e(b)             // get the estimates 
matrix x = b'               // transpose to a row vector
svmat double x              // save as a variable
rename x1 x_appx_rew_10_0   // named x_*

qui epctile rho_10_risk_43, svy percentiles($p_list) 
matrix b = e(b)             // get the estimates 
matrix x = b'               // transpose to a row vector
svmat double x              // save as a variable
rename x1 x_risk_43          // named x_*


* Centiles estimation for each bootstrap resampling (slow code here!)
*********************************************************************

forvalues b = 1/$B {
  qui epctile rho_10_`b', svy percentiles($p_list) 
  matrix b = e(b) 
  matrix x = b'
  svmat double x
  rename x1 x_10_`b'
}

* Inference using the boostrapped cdf
unab resamplings : x_10_*
egen x_ci_low = rowpctile(`resamplings'), p(5) 
egen x_avg = rowmean(`resamplings')
egen x_ci_high = rowpctile(`resamplings'), p(95) 

* Store bootstrapped cdfs
drop if missing(y)
keep y x_05_0 x_10_0 x_15_0 x_ci_low x_avg x_ci_high x_10_* avg_r x_appx_rew_10_0 x_risk_43
save "${analysis}/data/5_cdf.dta", replace


*********************************
* Domestic workers as employees *
*********************************

use "${analysis}/data/5_model_pieces.dta", clear

* Focus on OAW only (IBGE's default)
tab work_state_ibge_name
gen       appx_dom_winc_oaw = winc if work_state_ibge_name == "Own-account worker"
label var appx_dom_winc_oaw "Own-account workers' net available work income (IBGE default)"
keep if !missing(appx_dom_winc_oaw)
tab work_state_ibge_name


* Part A. Estimating rho
************************

* Estimated prob of acceptable offer
gen appx_dom_prob_accept_10_0 = 1 - normal( (appx_dom_est_ln_rw_10_0 - appx_dom_est_ln_wage_0) / appx_dom_est_ln_wage_sd )
sum appx_dom_prob_accept_10_0 [fweight = fweight], detail

* Estimated duration of unemployment
gen appx_dom_avg_unemp = 1 / appx_dom_haz_from_u_to_e_0
sum appx_dom_haz_from_u_to_e_0 appx_dom_avg_unemp [fweight = fweight], detail

* Estimated offer arrival rate lambda
gen appx_dom_l_10_0  = appx_dom_haz_from_u_to_e_0 / appx_dom_prob_accept_10_0

* Estimated wait time for an offer
gen appx_dom_avg_wait_10_0 = 1 / appx_dom_l_10_0
sum appx_dom_l_10_0 appx_dom_avg_wait_10_0 [fweight = fweight], detail


* Estimate rho lower bound (baseline and alternative specs)
***********************************************************

gen appx_dom_rho_10_0  = (appx_dom_l_10_0 / appx_dom_winc_oaw) * (appx_dom_est_wage_0 - appx_dom_est_rw_10_0 * appx_dom_prob_accept_10_0) - appx_dom_haz_out_of_e_0
sum appx_dom_rho_10_0 [fweight = fweight], detail

drop appx_dom_est_ln_wage_* appx_dom_est_wage_* appx_dom_est_ln_rw_* appx_dom_est_rw_* appx_dom_haz_from_u_to_e_* appx_dom_haz_out_of_e_* appx_dom_prob_accept_* appx_dom_l_* appx_dom_avg_unemp appx_dom_avg_wait_10_0
save "${analysis}/data/5_appx_dom_est_boot_rho.dta", replace


* Part B. Calculating the CDF
*****************************

svyset psu_id [pweight = pweight], strata(strata_id) singleunit(centered) 


* Summary of rho
****************

svy: mean appx_dom_rho_10_0
epctile appx_dom_rho_10_0, svy percentiles(1 25 50 75 99)
svy: mean appx_dom_rho_10_0 if appx_dom_rho_10_0 > -0.124 & appx_dom_rho_10_0 < 2.522 


* Empirical CDF
***************

* Centiles of interest: y-axis goes from .01 to .99 in steps of .0025
gen double y = _n/400 + 0.0075 if _n < 394

* Centiles of interest: same thing, in a list to be passed to the command epctile 
numlist "1(0.25)99"
global p_list = "`r(numlist)'"


* Centiles estimation for alternative specifications
****************************************************

qui epctile appx_dom_rho_10_0, svy percentiles($p_list) 
matrix b = e(b)             // get the estimates 
matrix x = b'               // transpose to a row vector
svmat double x              // save as a variable
rename x1 x_appx_dom_10_0   // named x_*

* Store bootstrapped cdf
drop if missing(y)
keep y x_appx_dom_10_0

* Merge with previous estimations
merge 1:1 y using "${analysis}/data/5_cdf.dta", nogenerate
describe
save "${analysis}/data/5_cdf.dta", replace


*****************
* Part C. Plots *
*****************

use "${analysis}/data/5_cdf.dta", clear

* Share of constrained OAW in each specification
foreach spec in "05_0" "10_0" "15_0" "ci_low" "avg" "ci_high" "appx_dom_10_0" "appx_rew_10_0" "risk_43" {
  gen step_0 = (x_`spec' > $avg_r)
  gen step_1 = step_0[_n] - step_0[_n-1]
  gen step_2 = y*step_1
  egen F_`spec' = total(step_2)
  global F_`spec' = F_`spec'[1]
  global constr_`spec' = 1 - F_`spec'[1]
  drop step_0 step_1 step_2 F_`spec'
}


* Graphical labels and aux parameters
*************************************

global ci_low = round($F_ci_low, .001)
global ci_high = round($F_ci_high, .001)

global perc_ci_low  = round($F_ci_low, .01) 
global perc_avg     = round($F_avg, .01) 
global perc_ci_high = round($F_ci_high, .01) 

global perc_constr_ci_low = round(100*$constr_ci_low, .1) 
global perc_constr_avg = round(100*$constr_avg, .1) 
global perc_constr_ci_high = round(100*$constr_ci_high, .1) 

global perc_05 = round($F_05_0, .01)
global perc_10 = round($F_10_0, .01)
global perc_15 = round($F_15_0, .01)

global perc_constr_05 = round(100*$constr_05_0, .1)
global perc_constr_10 = round(100*$constr_10_0, .1)
global perc_constr_15 = round(100*$constr_15_0, .1)

global appx_dom_perc_10 = round($F_appx_dom_10_0, .01)
global appx_rew_perc_10 = round($F_appx_rew_10_0, .01)

global appx_dom_perc_constr_10 = round(100*$constr_appx_dom_10_0, .1)
global appx_rew_perc_constr_10 = round(100*$constr_appx_rew_10_0, .1)

global perc_risk_43 = round($F_risk_43, .01)
global perc_constr_risk_43 = round($constr_risk_43, .01)

macro list

* Ratios and regions
global plotratio graphregion(margin(l+14 r+52)) plotregion(margin(l-1 r-1))

* Auxiliary parameters for the axis
global lr -0.12 // lower x range
global ur  0.24 // upper x range

global options_for_x_axis ///
  xlabel(-.12 "-12" -.08 "-8" -.04 "-4" 0 "0" .04 "4" .08 "8" .12 "12" .16 "16" .2 "20" .24 "24") ///
  xtitle("{bf:Discount rate lower bound for OAWs}" "{bf:(in percent per month)}", linegap(tiny))

global options_for_y_axis ///
  ylabel(0 (0.1) 1, format(%9.1g)) ///
  ytitle("{bf:Share of}" "{bf:own-account}" "{bf:workers}", placement(n) orient(horizontal) j(right) linegap(minuscule))

* Graphical adjustments
global lr_plus = $lr + .005

* Line defs
global lw 0.09
global lw_main 0.4
global lc black*0.2


* Plot structure
****************

graph twoway ///
  (scatteri $F_ci_low $lr $F_ci_low $ur $F_ci_high $ur $F_ci_high $lr, recast(area) color(gs14) lw(0) base($F_avg)) ///
  (pci $F_avg $lr $F_avg $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci 0 $avg_r $F_avg $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) ///
  (line y x_10_0 if x_10_0 > $lr & x_10_0 < $ur, sort lw(0.7) lc(black)) ///
  (scatteri $F_avg $lr $F_avg $lr_plus, recast(line) lp(l) lw($lw_main) lc(gs7)) ///
  (scatteri $F_avg $lr_plus 1.003 $lr_plus, recast(line) lp(l) lw($lw_main) lc(gs7)) ///
  (scatteri 1 $lr 1 $lr_plus, recast(line) lp(l) lw($lw_main) lc(gs7)), ///
  text($F_avg 0.253 "95% CI: [$perc_ci_high, $perc_ci_low]", place(e) just(left)) ///  
  text(0.73 -0.108 "{it:$perc_constr_avg% of own-account workers}", place(se) just(left)) ///
  text(0.09 0.046 "{it:market}" "{it:rate}", place(se) just(left)) ///
  $plotratio $options_for_y_axis $options_for_x_axis legend(off)

gr_edit yaxis1.title.DragBy -2 3


* FIGURE 3
**********

graph twoway ///
  (scatteri $F_ci_low $lr $F_ci_low $ur $F_ci_high $ur $F_ci_high $lr, recast(area) color(gs14) lw(0) base($F_avg)) ///
  (line y x_10_1 if x_10_1 > $lr & x_10_1 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_2 if x_10_2 > $lr & x_10_2 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_3 if x_10_3 > $lr & x_10_3 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_4 if x_10_4 > $lr & x_10_4 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_5 if x_10_5 > $lr & x_10_5 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_6 if x_10_6 > $lr & x_10_6 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_7 if x_10_7 > $lr & x_10_7 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_8 if x_10_8 > $lr & x_10_8 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_9 if x_10_9 > $lr & x_10_9 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_10 if x_10_10 > $lr & x_10_10 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_11 if x_10_11 > $lr & x_10_11 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_12 if x_10_12 > $lr & x_10_12 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_13 if x_10_13 > $lr & x_10_13 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_14 if x_10_14 > $lr & x_10_14 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_15 if x_10_15 > $lr & x_10_15 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_16 if x_10_16 > $lr & x_10_16 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_17 if x_10_17 > $lr & x_10_17 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_18 if x_10_18 > $lr & x_10_18 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_19 if x_10_19 > $lr & x_10_19 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_20 if x_10_20 > $lr & x_10_20 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_21 if x_10_21 > $lr & x_10_21 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_22 if x_10_22 > $lr & x_10_22 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_23 if x_10_23 > $lr & x_10_23 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_24 if x_10_24 > $lr & x_10_24 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_25 if x_10_25 > $lr & x_10_25 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_26 if x_10_26 > $lr & x_10_26 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_27 if x_10_27 > $lr & x_10_27 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_28 if x_10_28 > $lr & x_10_28 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_29 if x_10_29 > $lr & x_10_29 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_30 if x_10_30 > $lr & x_10_30 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_31 if x_10_31 > $lr & x_10_31 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_32 if x_10_32 > $lr & x_10_32 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_33 if x_10_33 > $lr & x_10_33 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_34 if x_10_34 > $lr & x_10_34 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_35 if x_10_35 > $lr & x_10_35 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_36 if x_10_36 > $lr & x_10_36 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_37 if x_10_37 > $lr & x_10_37 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_38 if x_10_38 > $lr & x_10_38 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_39 if x_10_39 > $lr & x_10_39 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_40 if x_10_40 > $lr & x_10_40 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_41 if x_10_41 > $lr & x_10_41 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_42 if x_10_42 > $lr & x_10_42 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_43 if x_10_43 > $lr & x_10_43 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_44 if x_10_44 > $lr & x_10_44 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_45 if x_10_45 > $lr & x_10_45 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_46 if x_10_46 > $lr & x_10_46 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_47 if x_10_47 > $lr & x_10_47 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_48 if x_10_48 > $lr & x_10_48 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_49 if x_10_49 > $lr & x_10_49 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_50 if x_10_50 > $lr & x_10_50 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_51 if x_10_51 > $lr & x_10_51 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_52 if x_10_52 > $lr & x_10_52 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_53 if x_10_53 > $lr & x_10_53 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_54 if x_10_54 > $lr & x_10_54 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_55 if x_10_55 > $lr & x_10_55 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_56 if x_10_56 > $lr & x_10_56 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_57 if x_10_57 > $lr & x_10_57 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_58 if x_10_58 > $lr & x_10_58 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_59 if x_10_59 > $lr & x_10_59 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_60 if x_10_60 > $lr & x_10_60 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_61 if x_10_61 > $lr & x_10_61 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_62 if x_10_62 > $lr & x_10_62 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_63 if x_10_63 > $lr & x_10_63 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_64 if x_10_64 > $lr & x_10_64 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_65 if x_10_65 > $lr & x_10_65 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_66 if x_10_66 > $lr & x_10_66 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_67 if x_10_67 > $lr & x_10_67 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_68 if x_10_68 > $lr & x_10_68 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_69 if x_10_69 > $lr & x_10_69 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_70 if x_10_70 > $lr & x_10_70 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_71 if x_10_71 > $lr & x_10_71 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_72 if x_10_72 > $lr & x_10_72 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_73 if x_10_73 > $lr & x_10_73 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_74 if x_10_74 > $lr & x_10_74 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_75 if x_10_75 > $lr & x_10_75 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_76 if x_10_76 > $lr & x_10_76 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_77 if x_10_77 > $lr & x_10_77 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_78 if x_10_78 > $lr & x_10_78 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_79 if x_10_79 > $lr & x_10_79 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_80 if x_10_80 > $lr & x_10_80 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_81 if x_10_81 > $lr & x_10_81 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_82 if x_10_82 > $lr & x_10_82 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_83 if x_10_83 > $lr & x_10_83 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_84 if x_10_84 > $lr & x_10_84 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_85 if x_10_85 > $lr & x_10_85 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_86 if x_10_86 > $lr & x_10_86 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_87 if x_10_87 > $lr & x_10_87 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_88 if x_10_88 > $lr & x_10_88 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_89 if x_10_89 > $lr & x_10_89 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_90 if x_10_90 > $lr & x_10_90 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_91 if x_10_91 > $lr & x_10_91 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_92 if x_10_92 > $lr & x_10_92 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_93 if x_10_93 > $lr & x_10_93 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_94 if x_10_94 > $lr & x_10_94 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_95 if x_10_95 > $lr & x_10_95 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_96 if x_10_96 > $lr & x_10_96 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_97 if x_10_97 > $lr & x_10_97 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_98 if x_10_98 > $lr & x_10_98 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_99 if x_10_99 > $lr & x_10_99 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_100 if x_10_100 > $lr & x_10_100 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_101 if x_10_101 > $lr & x_10_101 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_102 if x_10_102 > $lr & x_10_102 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_103 if x_10_103 > $lr & x_10_103 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_104 if x_10_104 > $lr & x_10_104 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_105 if x_10_105 > $lr & x_10_105 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_106 if x_10_106 > $lr & x_10_106 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_107 if x_10_107 > $lr & x_10_107 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_108 if x_10_108 > $lr & x_10_108 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_109 if x_10_109 > $lr & x_10_109 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_110 if x_10_110 > $lr & x_10_110 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_111 if x_10_111 > $lr & x_10_111 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_112 if x_10_112 > $lr & x_10_112 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_113 if x_10_113 > $lr & x_10_113 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_114 if x_10_114 > $lr & x_10_114 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_115 if x_10_115 > $lr & x_10_115 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_116 if x_10_116 > $lr & x_10_116 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_117 if x_10_117 > $lr & x_10_117 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_118 if x_10_118 > $lr & x_10_118 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_119 if x_10_119 > $lr & x_10_119 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_120 if x_10_120 > $lr & x_10_120 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_121 if x_10_121 > $lr & x_10_121 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_122 if x_10_122 > $lr & x_10_122 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_123 if x_10_123 > $lr & x_10_123 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_124 if x_10_124 > $lr & x_10_124 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_125 if x_10_125 > $lr & x_10_125 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_126 if x_10_126 > $lr & x_10_126 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_127 if x_10_127 > $lr & x_10_127 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_128 if x_10_128 > $lr & x_10_128 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_129 if x_10_129 > $lr & x_10_129 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_130 if x_10_130 > $lr & x_10_130 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_131 if x_10_131 > $lr & x_10_131 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_132 if x_10_132 > $lr & x_10_132 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_133 if x_10_133 > $lr & x_10_133 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_134 if x_10_134 > $lr & x_10_134 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_135 if x_10_135 > $lr & x_10_135 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_136 if x_10_136 > $lr & x_10_136 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_137 if x_10_137 > $lr & x_10_137 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_138 if x_10_138 > $lr & x_10_138 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_139 if x_10_139 > $lr & x_10_139 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_140 if x_10_140 > $lr & x_10_140 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_141 if x_10_141 > $lr & x_10_141 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_142 if x_10_142 > $lr & x_10_142 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_143 if x_10_143 > $lr & x_10_143 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_144 if x_10_144 > $lr & x_10_144 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_145 if x_10_145 > $lr & x_10_145 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_146 if x_10_146 > $lr & x_10_146 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_147 if x_10_147 > $lr & x_10_147 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_148 if x_10_148 > $lr & x_10_148 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_149 if x_10_149 > $lr & x_10_149 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_150 if x_10_150 > $lr & x_10_150 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_151 if x_10_151 > $lr & x_10_151 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_152 if x_10_152 > $lr & x_10_152 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_153 if x_10_153 > $lr & x_10_153 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_154 if x_10_154 > $lr & x_10_154 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_155 if x_10_155 > $lr & x_10_155 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_156 if x_10_156 > $lr & x_10_156 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_157 if x_10_157 > $lr & x_10_157 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_158 if x_10_158 > $lr & x_10_158 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_159 if x_10_159 > $lr & x_10_159 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_160 if x_10_160 > $lr & x_10_160 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_161 if x_10_161 > $lr & x_10_161 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_162 if x_10_162 > $lr & x_10_162 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_163 if x_10_163 > $lr & x_10_163 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_164 if x_10_164 > $lr & x_10_164 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_165 if x_10_165 > $lr & x_10_165 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_166 if x_10_166 > $lr & x_10_166 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_167 if x_10_167 > $lr & x_10_167 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_168 if x_10_168 > $lr & x_10_168 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_169 if x_10_169 > $lr & x_10_169 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_170 if x_10_170 > $lr & x_10_170 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_171 if x_10_171 > $lr & x_10_171 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_172 if x_10_172 > $lr & x_10_172 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_173 if x_10_173 > $lr & x_10_173 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_174 if x_10_174 > $lr & x_10_174 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_175 if x_10_175 > $lr & x_10_175 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_176 if x_10_176 > $lr & x_10_176 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_177 if x_10_177 > $lr & x_10_177 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_178 if x_10_178 > $lr & x_10_178 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_179 if x_10_179 > $lr & x_10_179 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_180 if x_10_180 > $lr & x_10_180 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_181 if x_10_181 > $lr & x_10_181 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_182 if x_10_182 > $lr & x_10_182 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_183 if x_10_183 > $lr & x_10_183 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_184 if x_10_184 > $lr & x_10_184 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_185 if x_10_185 > $lr & x_10_185 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_186 if x_10_186 > $lr & x_10_186 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_187 if x_10_187 > $lr & x_10_187 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_188 if x_10_188 > $lr & x_10_188 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_189 if x_10_189 > $lr & x_10_189 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_190 if x_10_190 > $lr & x_10_190 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_191 if x_10_191 > $lr & x_10_191 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_192 if x_10_192 > $lr & x_10_192 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_193 if x_10_193 > $lr & x_10_193 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_194 if x_10_194 > $lr & x_10_194 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_195 if x_10_195 > $lr & x_10_195 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_196 if x_10_196 > $lr & x_10_196 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_197 if x_10_197 > $lr & x_10_197 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_198 if x_10_198 > $lr & x_10_198 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_199 if x_10_199 > $lr & x_10_199 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_200 if x_10_200 > $lr & x_10_200 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_201 if x_10_201 > $lr & x_10_201 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_202 if x_10_202 > $lr & x_10_202 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_203 if x_10_203 > $lr & x_10_203 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_204 if x_10_204 > $lr & x_10_204 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_205 if x_10_205 > $lr & x_10_205 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_206 if x_10_206 > $lr & x_10_206 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_207 if x_10_207 > $lr & x_10_207 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_208 if x_10_208 > $lr & x_10_208 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_209 if x_10_209 > $lr & x_10_209 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_210 if x_10_210 > $lr & x_10_210 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_211 if x_10_211 > $lr & x_10_211 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_212 if x_10_212 > $lr & x_10_212 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_213 if x_10_213 > $lr & x_10_213 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_214 if x_10_214 > $lr & x_10_214 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_215 if x_10_215 > $lr & x_10_215 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_216 if x_10_216 > $lr & x_10_216 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_217 if x_10_217 > $lr & x_10_217 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_218 if x_10_218 > $lr & x_10_218 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_219 if x_10_219 > $lr & x_10_219 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_220 if x_10_220 > $lr & x_10_220 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_221 if x_10_221 > $lr & x_10_221 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_222 if x_10_222 > $lr & x_10_222 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_223 if x_10_223 > $lr & x_10_223 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_224 if x_10_224 > $lr & x_10_224 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_225 if x_10_225 > $lr & x_10_225 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_226 if x_10_226 > $lr & x_10_226 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_227 if x_10_227 > $lr & x_10_227 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_228 if x_10_228 > $lr & x_10_228 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_229 if x_10_229 > $lr & x_10_229 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_230 if x_10_230 > $lr & x_10_230 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_231 if x_10_231 > $lr & x_10_231 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_232 if x_10_232 > $lr & x_10_232 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_233 if x_10_233 > $lr & x_10_233 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_234 if x_10_234 > $lr & x_10_234 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_235 if x_10_235 > $lr & x_10_235 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_236 if x_10_236 > $lr & x_10_236 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_237 if x_10_237 > $lr & x_10_237 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_238 if x_10_238 > $lr & x_10_238 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_239 if x_10_239 > $lr & x_10_239 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_240 if x_10_240 > $lr & x_10_240 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_241 if x_10_241 > $lr & x_10_241 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_242 if x_10_242 > $lr & x_10_242 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_243 if x_10_243 > $lr & x_10_243 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_244 if x_10_244 > $lr & x_10_244 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_245 if x_10_245 > $lr & x_10_245 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_246 if x_10_246 > $lr & x_10_246 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_247 if x_10_247 > $lr & x_10_247 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_248 if x_10_248 > $lr & x_10_248 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_249 if x_10_249 > $lr & x_10_249 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_250 if x_10_250 > $lr & x_10_250 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_251 if x_10_251 > $lr & x_10_251 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_252 if x_10_252 > $lr & x_10_252 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_253 if x_10_253 > $lr & x_10_253 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_254 if x_10_254 > $lr & x_10_254 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_255 if x_10_255 > $lr & x_10_255 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_256 if x_10_256 > $lr & x_10_256 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_257 if x_10_257 > $lr & x_10_257 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_258 if x_10_258 > $lr & x_10_258 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_259 if x_10_259 > $lr & x_10_259 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_260 if x_10_260 > $lr & x_10_260 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_261 if x_10_261 > $lr & x_10_261 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_262 if x_10_262 > $lr & x_10_262 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_263 if x_10_263 > $lr & x_10_263 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_264 if x_10_264 > $lr & x_10_264 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_265 if x_10_265 > $lr & x_10_265 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_266 if x_10_266 > $lr & x_10_266 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_267 if x_10_267 > $lr & x_10_267 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_268 if x_10_268 > $lr & x_10_268 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_269 if x_10_269 > $lr & x_10_269 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_270 if x_10_270 > $lr & x_10_270 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_271 if x_10_271 > $lr & x_10_271 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_272 if x_10_272 > $lr & x_10_272 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_273 if x_10_273 > $lr & x_10_273 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_274 if x_10_274 > $lr & x_10_274 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_275 if x_10_275 > $lr & x_10_275 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_276 if x_10_276 > $lr & x_10_276 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_277 if x_10_277 > $lr & x_10_277 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_278 if x_10_278 > $lr & x_10_278 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_279 if x_10_279 > $lr & x_10_279 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_280 if x_10_280 > $lr & x_10_280 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_281 if x_10_281 > $lr & x_10_281 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_282 if x_10_282 > $lr & x_10_282 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_283 if x_10_283 > $lr & x_10_283 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_284 if x_10_284 > $lr & x_10_284 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_285 if x_10_285 > $lr & x_10_285 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_286 if x_10_286 > $lr & x_10_286 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_287 if x_10_287 > $lr & x_10_287 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_288 if x_10_288 > $lr & x_10_288 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_289 if x_10_289 > $lr & x_10_289 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_290 if x_10_290 > $lr & x_10_290 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_291 if x_10_291 > $lr & x_10_291 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_292 if x_10_292 > $lr & x_10_292 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_293 if x_10_293 > $lr & x_10_293 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_294 if x_10_294 > $lr & x_10_294 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_295 if x_10_295 > $lr & x_10_295 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_296 if x_10_296 > $lr & x_10_296 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_297 if x_10_297 > $lr & x_10_297 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_298 if x_10_298 > $lr & x_10_298 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_299 if x_10_299 > $lr & x_10_299 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_300 if x_10_300 > $lr & x_10_300 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_301 if x_10_301 > $lr & x_10_301 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_302 if x_10_302 > $lr & x_10_302 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_303 if x_10_303 > $lr & x_10_303 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_304 if x_10_304 > $lr & x_10_304 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_305 if x_10_305 > $lr & x_10_305 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_306 if x_10_306 > $lr & x_10_306 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_307 if x_10_307 > $lr & x_10_307 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_308 if x_10_308 > $lr & x_10_308 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_309 if x_10_309 > $lr & x_10_309 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_310 if x_10_310 > $lr & x_10_310 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_311 if x_10_311 > $lr & x_10_311 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_312 if x_10_312 > $lr & x_10_312 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_313 if x_10_313 > $lr & x_10_313 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_314 if x_10_314 > $lr & x_10_314 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_315 if x_10_315 > $lr & x_10_315 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_316 if x_10_316 > $lr & x_10_316 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_317 if x_10_317 > $lr & x_10_317 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_318 if x_10_318 > $lr & x_10_318 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_319 if x_10_319 > $lr & x_10_319 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_320 if x_10_320 > $lr & x_10_320 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_321 if x_10_321 > $lr & x_10_321 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_322 if x_10_322 > $lr & x_10_322 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_323 if x_10_323 > $lr & x_10_323 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_324 if x_10_324 > $lr & x_10_324 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_325 if x_10_325 > $lr & x_10_325 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_326 if x_10_326 > $lr & x_10_326 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_327 if x_10_327 > $lr & x_10_327 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_328 if x_10_328 > $lr & x_10_328 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_329 if x_10_329 > $lr & x_10_329 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_330 if x_10_330 > $lr & x_10_330 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_331 if x_10_331 > $lr & x_10_331 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_332 if x_10_332 > $lr & x_10_332 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_333 if x_10_333 > $lr & x_10_333 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_334 if x_10_334 > $lr & x_10_334 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_335 if x_10_335 > $lr & x_10_335 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_336 if x_10_336 > $lr & x_10_336 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_337 if x_10_337 > $lr & x_10_337 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_338 if x_10_338 > $lr & x_10_338 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_339 if x_10_339 > $lr & x_10_339 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_340 if x_10_340 > $lr & x_10_340 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_341 if x_10_341 > $lr & x_10_341 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_342 if x_10_342 > $lr & x_10_342 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_343 if x_10_343 > $lr & x_10_343 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_344 if x_10_344 > $lr & x_10_344 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_345 if x_10_345 > $lr & x_10_345 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_346 if x_10_346 > $lr & x_10_346 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_347 if x_10_347 > $lr & x_10_347 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_348 if x_10_348 > $lr & x_10_348 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_349 if x_10_349 > $lr & x_10_349 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_350 if x_10_350 > $lr & x_10_350 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_351 if x_10_351 > $lr & x_10_351 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_352 if x_10_352 > $lr & x_10_352 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_353 if x_10_353 > $lr & x_10_353 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_354 if x_10_354 > $lr & x_10_354 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_355 if x_10_355 > $lr & x_10_355 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_356 if x_10_356 > $lr & x_10_356 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_357 if x_10_357 > $lr & x_10_357 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_358 if x_10_358 > $lr & x_10_358 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_359 if x_10_359 > $lr & x_10_359 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_360 if x_10_360 > $lr & x_10_360 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_361 if x_10_361 > $lr & x_10_361 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_362 if x_10_362 > $lr & x_10_362 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_363 if x_10_363 > $lr & x_10_363 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_364 if x_10_364 > $lr & x_10_364 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_365 if x_10_365 > $lr & x_10_365 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_366 if x_10_366 > $lr & x_10_366 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_367 if x_10_367 > $lr & x_10_367 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_368 if x_10_368 > $lr & x_10_368 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_369 if x_10_369 > $lr & x_10_369 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_370 if x_10_370 > $lr & x_10_370 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_371 if x_10_371 > $lr & x_10_371 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_372 if x_10_372 > $lr & x_10_372 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_373 if x_10_373 > $lr & x_10_373 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_374 if x_10_374 > $lr & x_10_374 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_375 if x_10_375 > $lr & x_10_375 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_376 if x_10_376 > $lr & x_10_376 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_377 if x_10_377 > $lr & x_10_377 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_378 if x_10_378 > $lr & x_10_378 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_379 if x_10_379 > $lr & x_10_379 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_380 if x_10_380 > $lr & x_10_380 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_381 if x_10_381 > $lr & x_10_381 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_382 if x_10_382 > $lr & x_10_382 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_383 if x_10_383 > $lr & x_10_383 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_384 if x_10_384 > $lr & x_10_384 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_385 if x_10_385 > $lr & x_10_385 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_386 if x_10_386 > $lr & x_10_386 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_387 if x_10_387 > $lr & x_10_387 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_388 if x_10_388 > $lr & x_10_388 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_389 if x_10_389 > $lr & x_10_389 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_390 if x_10_390 > $lr & x_10_390 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_391 if x_10_391 > $lr & x_10_391 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_392 if x_10_392 > $lr & x_10_392 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_393 if x_10_393 > $lr & x_10_393 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_394 if x_10_394 > $lr & x_10_394 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_395 if x_10_395 > $lr & x_10_395 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_396 if x_10_396 > $lr & x_10_396 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_397 if x_10_397 > $lr & x_10_397 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_398 if x_10_398 > $lr & x_10_398 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_399 if x_10_399 > $lr & x_10_399 < $ur, sort lw($lw) lc($lc)) ///
  (line y x_10_400 if x_10_400 > $lr & x_10_400 < $ur, sort lw($lw) lc($lc)) ///
  (pci $F_avg $lr $F_avg $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci 0 $avg_r $F_avg $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) ///
  (line y x_10_0 if x_10_0 > $lr & x_10_0 < $ur, sort lw(0.7) lc(black)) ///
  (scatteri $F_avg $lr $F_avg $lr_plus, recast(line) lp(l) lw($lw_main) lc(gs7)) ///
  (scatteri $F_avg $lr_plus 1.003 $lr_plus, recast(line) lp(l) lw($lw_main) lc(gs7)) ///
  (scatteri 1 $lr 1 $lr_plus, recast(line) lp(l) lw($lw_main) lc(gs7)), ///
  text($F_avg 0.253 "95% CI: [$perc_ci_high, $perc_ci_low]", place(e) just(left)) ///  
  text(0.73 -0.108 "{it:$perc_constr_avg% of own-account workers}", place(se) just(left)) ///
  text(0.09 0.046 "{it:market}" "{it:rate}", place(se) just(left)) ///
  $plotratio $options_for_y_axis $options_for_x_axis legend(off)

gr_edit yaxis1.title.DragBy -2 3

graph export "${analysis}/results/figures/fig3.eps", replace


* Alternative specifications: risk aversion (FIGURE 5)
******************************************************

graph twoway ///
  (pci $F_risk_43  $lr $F_risk_43  $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci $F_10_0    $lr $F_10_0    $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci 0 $avg_r $F_risk_43 $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) ///
  (line y x_risk_43 if x_risk_43 > $lr & x_risk_43 < $ur, sort lw(0.7) lc(black*.5)) ///
  (line y x_10_0 if x_10_0 > $lr & x_10_0 < $ur, sort lw(0.7) lc(black)), ///
  text(0.71 0.252 "Risk neutrality ({&gamma} = 0, {it:baseline})", place(e) just(left)) ///  
  text(0.95 0.252 "Risk aversion ({&gamma} = .43)", place(e) just(left)) ///  
  text(0.38 -0.12 "{it:$perc_10}", place(e) just(left)) ///  
  text(0.68 -0.12 "{it:$perc_risk_43}", place(e) just(left)) ///  
  text(0.09 0.046 "{it:market}" "{it:rate}", place(se) just(left)) ///
  $plotratio $options_for_y_axis $options_for_x_axis legend(off)

gr_edit yaxis1.title.DragBy -2 3

graph export "${analysis}/results/figures/fig5.eps", replace


* Alternative specifications: domestic workers as employees (FIGURE 7)
**********************************************************************

graph twoway ///
  (pci $F_10_0 $lr $F_10_0 $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci $F_appx_dom_10_0 $lr $F_appx_dom_10_0 $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci 0 $avg_r $F_avg $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) ///
  (line y x_10_0 if x_10_0 > $lr & x_10_0 < $ur, sort lw(0.7) lc(black)) ///
  (line y x_appx_dom_10_0 if x_appx_dom_10_0 > $lr & x_appx_dom_10_0 < $ur, sort lw(0.7) lc(black*.5)), ///
  text(0.73 0.252 "Dom. worker as OAW {it:(baseline)}", place(e) just(left)) ///  
  text(0.66 0.252 "Dom. worker as employee", place(e) just(left)) ///  
  text(0.38 -0.12 "{it:$perc_10}", place(e) just(left)) ///  
  text(0.31 -0.12 "{it:$appx_dom_perc_10}", place(e) just(left)) ///  
  text(0.09 0.046 "{it:market}" "{it:rate}", place(se) just(left)) ///
  $plotratio $options_for_y_axis $options_for_x_axis legend(off)

gr_edit yaxis1.title.DragBy -2 3

graph export "${analysis}/results/figures/fig7.eps", replace


* Alternative specifications: quantiles 5 10 15 (FIGURE 8)
**********************************************************

graph twoway ///
  (pci $F_15_0    $lr $F_15_0    $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci $F_10_0    $lr $F_10_0    $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci $F_05_0    $lr $F_05_0    $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci 0 $avg_r .37 $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) ///
  (line y x_15_0 if x_15_0 > $lr & x_15_0 < $ur, sort lw(0.7) lc(black*.2)) ///
  (line y x_10_0 if x_10_0 > $lr & x_10_0 < $ur, sort lw(0.7) lc(black)) ///
  (line y x_05_0 if x_05_0 > $lr & x_05_0 < $ur, sort lw(0.7) lc(black*.5)), ///
  text(0.77 0.252 "Reserv. wage at .15", place(e) just(left)) ///  
  text(0.71 0.252 "Reserv. wage at .10 {it:(baseline)}", place(e) just(left)) ///  
  text(0.65 0.252 "Reserv. wage at .05", place(e) just(left)) ///  
  text(0.415 -0.12 "{it:$perc_15}", place(e) just(left)) ///  
  text(0.275 -0.12 "{it:$perc_05}", place(e) just(left)) ///  
  text(0.09 0.046 "{it:market}" "{it:rate}", place(se) just(left)) ///
  $plotratio $options_for_y_axis $options_for_x_axis legend(off)

gr_edit yaxis1.title.DragBy -2 3

graph export "${analysis}/results/figures/fig8.eps", replace


* Alternative specifications: reweighted pnadc (FIGURE 9)
*********************************************************

graph twoway ///
  (pci $F_10_0 $lr $F_10_0 $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci $F_appx_rew_10_0 $lr $F_appx_rew_10_0 $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) /// 
  (pci 0 $avg_r $F_avg $avg_r, lw($lw_main) lc(gs7) lp(shortdash)) ///
  (line y x_10_0 if x_10_0 > $lr & x_10_0 < $ur, sort lw(0.7) lc(black)) ///
  (line y x_appx_rew_10_0 if x_appx_rew_10_0 > $lr & x_appx_rew_10_0 < $ur, sort lw(0.7) lc(black*.5)), ///
  text(0.74 0.252 "PNAD original weights {it:(baseline)}", place(e) just(left)) ///  
  text(0.69 0.252 "PNAD reweighted to match POF", place(e) just(left)) ///  
  text(0.38 -0.12 "{it:$perc_10}", place(e) just(left)) ///  
  text(0.31 -0.12 "{it:$appx_rew_perc_10}", place(e) just(left)) ///  
  text(0.09 0.046 "{it:market}" "{it:rate}", place(se) just(left)) ///
  $plotratio $options_for_y_axis $options_for_x_axis legend(off)

gr_edit yaxis1.title.DragBy -2 3

graph export "${analysis}/results/figures/fig9.eps", replace


* End of script
***************
cap log close